﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Data;
using ProjectBase.Data.NH;

using Survey.Common.Data;
using Survey.Entity;

namespace Survey.Data
{
    public abstract class CodeListBaseDao<T, TFilter> : BaseDao<T, int, TFilter>, ICodeListDao<T, TFilter>
        where T : class, ICodeList
        where TFilter : CodeListFilter, new()
    {
        #region ICodeListDao<T,TFilter> Members
        /// <summary>
        ///     Evaluates all filters and order-by clauses
        ///     and returns sorted list of matching CodeList entities
        /// </summary>
        /// <param name = "filter">ISearchObject&lt;CodeList&gt; containing CodeListFilter not-null instance</param>
        /// <returns>List of CodeList entities matching the searching criteria</returns>
        public override IEnumerable<T> Find(TFilter filter)
        {
            Criteria.AddCompare(() => filter.IdExact); // Searches for exact ID
            Criteria.AddEqual(() => Entity.Code, filter.CodeExact); // Searches for exact match

            Criteria.AddLike(() => filter.Code);
            Criteria.AddLike(() => filter.Name);

            Criteria.AddEqual(() => Entity.IsVisible, filter.IsVisible); // Searches for exact match
            return GetListByCriteria(filter);
        }

        /// <summary>
        ///     Returns all Values.
        ///     On upper layer (e.g. Facade) it could be filtered for comboboxes
        ///     using the property IsVisible == true
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable<T> GetAll()
        {
            return Find(new TFilter { MaxRowsPerPage = int.MaxValue });
        }
        #endregion
    }
}